import apiClient from './client';
import { AppointApplySchema, AppointApplyResultSchema,AppointTimeDataItem, AppointApplyStudentSchema, WorkTimeItem } from '../types/appoint';


/**
 * 新增预约
 * @param appoint 预约数据
 * @returns 预约结果
 */
export const addAppointApplyApi = async (
    appoint: AppointApplySchema
): Promise<{
    code: number;
    message: string;
    data: AppointApplyResultSchema;
}> => {
    return apiClient.post('/api/appoint/v1/apply', {...appoint});
};

/**
 * 取消预约
 * @param appoint 预约数据
 * @returns 预约结果
 */
export const cancelAppointApplyApi = async (
    appoint_id: number,
    coach_id: number
): Promise<{
    code: number;
    message: string;
    data: boolean;
}> => {
    return apiClient.delete('/api/appoint/v1/apply', {
        appoint_id,
        coach_id
    });
};

/**
 * 获取我的预约
 * @param appoint 预约数据
 * @returns 预约结果
 */
export const getAppointApplyApi = async (
    coach_id: number,
    date: string
): Promise<{
    code: number;
    message: string;
    data: AppointApplyResultSchema;
}> => {
    return apiClient.get('/api/appoint/v1/apply', {
        coach_id,
        date
    });
};


/**
 * 获取预约结果
 * @param coach_id 教练id
 * @param date 日期
 * @returns 预约结果
 */
export const getAppointResultApi = async (
    coach_id: number,
    date: string,
    subject: number
): Promise<{
    code: number;
    message: string;
    data: {
        status: number;
        record: AppointTimeDataItem[];
    };
}> => {
    return apiClient.get('/api/appoint/v1/result', {
        coach_id,
        date,
        subject
    });
};

/**
 * 获取申请的学生信息
 * @param date 日期
 * @returns 预约结果
 */
export const getAppointStudentsApi = async (
    date: string
): Promise<{
    code: number;
    message: string;
    data: AppointApplyStudentSchema[]
}> => {
    return apiClient.get('/api/appoint/v1/students', { date });
};

/**
 * 获取教练的工作时间
 * @param date 日期
 * @returns 预约结果
 */
export const getAppointCoachWorktimeApi = async (): Promise<{
    code: number;
    message: string;
    data: WorkTimeItem
}> => {
    return apiClient.get('/api/appoint/v1/worktime');
};

/**
 * 更新教练的工作时间
 * @param date 日期
 * @returns 预约结果
 */
export const setAppointCoachWorktimeApi = async (startTime: string, endTime: string): Promise<{
    code: number;
    message: string;
}> => {
    return apiClient.post('/api/appoint/v1/worktime', {
        start_time: startTime,
        end_time: endTime,
    });
};

/**
 * 获取申请的结果信息
 * @param date 日期
 * @returns 预约结果
 */
export const getTodayAppointResultApi = async (
    date: string,
    subject: number
): Promise<{
    code: number;
    message: string;
    data: Array<Array<AppointTimeDataItem>>
}> => {
    return apiClient.get('/api/appoint/v1/today', { date, subject });
};

/**
 * 获取申请的学生信息
 * @param date 日期
 * @returns 预约结果
 */
export const setTodayAppointResultApi = async (
    date: string,
    result: Array<Array<AppointTimeDataItem>>,
    work_time: string[],
    subject: number,
): Promise<{
    code: number;
    message: string;
}> => {
    return apiClient.post('/api/appoint/v1/today', {
        date,
        subject,
        work_time,
        result,
    });
};

/**
 * 屏蔽学生当天的预约
 * @param date 日期
 * @param student_id 学生id
 * @returns 预约结果
 */
export const setStudentShieldApi = async (
    student_id: number,
    date: string,
    status: number,
): Promise<{
    code: number;
    message: string;
}> => {
    return apiClient.put('/api/appoint/v1/student', {
        student_id,
        date,
        status
    });
}
